﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
using COMOSOFT.Class;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraReports.UI;
using COMOSOFT.JobManagement.Report;
using System.IO;
using DevExpress.XtraEditors;
using COMOSOFT.JobManagement.USC;
using DevExpress.XtraScheduler;

namespace COMOSOFT.JobManagement.Froms
{
    public partial class FrmJobView : Form
    {       
        ClassShare cls = new ClassShare("FrmJobView");
        UscJobView uscJobView = null;
        UscSchedule uscSchedule = null;
        UscStaffInfo uscStaffInfo = null;
        public FrmJobView()
        {
            InitializeComponent();
            ClassShare.frjobview = this;
        }
        
        private void FrmJobView_Load(object sender, EventArgs e)
        {                   
        }
        public void LoadData()
        {
            panelControl.Controls.Clear();            
            DataTable dtb = cls.GetData("sp_JobCount", new string[] { "@EID" }, new object[] { ClassShare.Usid });
            bnt_All.Text = "ALL [" + dtb.Rows[0][0].ToString() + " Items]";
            bnt_Recive.Text = "Receive [" + dtb.Rows[0][1].ToString() + " Items]";
            bnt_Sent.Text = "Assign [" + dtb.Rows[0][2].ToString() + " Items]";
            bnt_CC.Text = "CC [" + dtb.Rows[0][3].ToString() + " Items]";

            uscJobView = new UscJobView();
            panelControl.Controls.Add(uscJobView); 
            uscJobView.Dock = DockStyle.Fill;
            uscJobView.Show();
            uscJobView.LoadData("All");        
        }        
        public void loadUscJobView(string type)
        {
            if(uscJobView!=null || !uscJobView.IsDisposed)
                uscJobView.LoadData(type); 
        }
        private void navBarGroup_ItemChanged(object sender, EventArgs e)
        {
            panelControl.Controls.Clear();
            switch (navBarControl_Job.ActiveGroup.Caption)
            {                   
                case "Jobs":
                        uscJobView = new UscJobView();
                        panelControl.Controls.Add(uscJobView); 
                        uscJobView.Dock = DockStyle.Fill;
                        uscJobView.Show();
                        uscJobView.LoadData("All");      
                    break;
                case "Calendar":
                        uscSchedule = new UscSchedule();
                        panelControl.Controls.Add(uscSchedule);
                        uscSchedule.Dock = DockStyle.Fill;
                        uscSchedule.Show();  
                        dateNavigator.SchedulerControl = uscSchedule.GetSchedule();
                    break;
                case "Contacts":
                    uscStaffInfo = new UscStaffInfo();
                    panelControl.Controls.Add(uscStaffInfo);
                    uscStaffInfo.Dock = DockStyle.Fill;
                    this.employeeTableAdapter.Fill(this.dataSetOrderManagement.Employee);
                    uscStaffInfo.Show();
                    break;
            }
        }
        private void bnt_All_Click(object sender, EventArgs e)
        {
            loadUscJobView("ALL"); 
        }

        private void bnt_Recive_Click(object sender, EventArgs e)
        {
            loadUscJobView("Receive"); 
        }

        private void bnt_Sent_Click(object sender, EventArgs e)
        {
            loadUscJobView("Assign"); 
        }

        private void bnt_CC_Click(object sender, EventArgs e)
        {
            loadUscJobView("CC"); 
        }

        private void gridView_Contacts_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
        {
            if (uscStaffInfo != null || !uscStaffInfo.IsDisposed)
            {
                uscStaffInfo.SelectItem(e.FocusedRowHandle);
            }
        }   
    }
}
